package tech.aistar.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import tech.aistar.model.pojo.Users;

import javax.servlet.http.HttpServletRequest;

/**
 * 本类用来演示: 接受参数
 *
 * @author: success
 * @date: 2021/4/29 9:37 上午
 */
//@RestController
@Controller
@RequestMapping("/param")
public class ParamController {
    /**
     * http://localhost:8089/boot/param/test01?username=admin&power=0
     *
     * 摆地摊- 保证参数的类型,参数名称和传过来的url后面的参数列表保持一致即可.
     * @param username
     * @param power
     * @return
     */
    @GetMapping("/test01")
    @ResponseBody
    public String test01(String username,Integer power){
        return "name:"+username+",power:"+power;
    }

    /**
     * http://localhost:8089/boot/param/test02?username=admin&power=100
     * 直接使用对象 - 对象的属性名和参数的key名保持一致即可.实现参数到实体类属性的自动绑定
     * @param users
     * @return
     */
    @GetMapping("/test02")
    @ResponseBody
    public String test02(Users users){
        //method.invoke(Object obj,Object args...)
        return "name=>"+users.getUsername()+",power=>"+users.getPower();
    }

    @PostMapping("/test03")
    @ResponseBody
    public String test03(Users users){
        //method.invoke(Object obj,Object args...)
        return "name=>>"+users.getUsername()+",power=>>"+users.getPower();
    }

    @GetMapping("/date")
    public String test04(){
        return "user/date";
    }

    /**
     * 接受Date
     * @param user
     * @return
     */
    @PostMapping("/dd")
    @ResponseBody
    public Users test05(Users user){
        return user;
    }

    @GetMapping("/login")
    @ResponseBody
    public Users test06(Users user){
        return user;
    }

    @PostMapping("/logins")
    @ResponseBody
    public Users test07(@RequestBody Users user){
        return user;
    }
}
